<?php include  APP_PATH.'../template/public/header.php'?>
<aside class="main-sidebar">
    <section class="sidebar">
        <?php include APP_PATH.'../template/public/navigation.php'?>
    </section>
</aside>
<div class="content-wrapper">
    <section class="content-header">
        <h1>
            {$title}
        </h1>

        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> {$title}</a></li>
        </ol>
    </section>
    <section class="content">
        <div class="box">
            <div class="box-body">
                <form id="form"  role="form" class="col-md-8">

                    <div class="form-group">
                        <label>父栏目名称</label>
                        <select id="fu_id" name="fu_id" class="form-control" style="width: 100%;" tabindex="-1" aria-hidden="true">
                            <option role="" value="" >顶级栏目</option>
                            <?php   foreach ($f as $v){?>
                            <option role="{$v.user_role}" value="{$v.id}" ><span style="float: left">{$v.name}</span>————<span style="float: right">{$v.role}</span></option>
                            <?php }?>
                        </select>
                    </div>
                    <div class="form-group" >
                        <label>属于角色</label>
                        <select id="role" name="role" class="form-control" style="width: 100%;" tabindex="-1" aria-hidden="true">
                            <option value="0">管理员</option>
                            <option value="1">代理商</option>
                            <option value="2">子账户</option>
                            <option value="3">广告主</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="name">栏目名称</label>
                        <input type="text" name="name" class="form-control" id="name" placeholder="请输入名称">
                    </div>
                    <div class="form-group">
                        <label for="url">栏目链接</label>
                        <input type="text" name="url" class="form-control" id="url" placeholder="请输入链接">
                    </div>
                    <div class="form-group">
                        <label for="sort">栏目排序</label>
                        <input type="text" name="sort" class="form-control" id="sort" placeholder="请输入名称">
                    </div>
                    <div class="form-group">
                        <button id="submit"  class="btn btn-default">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </section>
</div>
<?php include APP_PATH.'../template/public/footer.php'; ?>
<script>
    $('#fu_id').change(function () {
        var vs = $('#fu_id  option:selected').val();
        var role = $('#fu_id  option:selected').attr('role');
        if(role){
            $('#role').val(role);
            $("#role").attr("disabled","disabled")
        }else{
            $('#role').val(0);
            $("#role").removeAttr("disabled");
        }

    })

        $('#submit').click(function () {
            var data = {};
            var t = $('#form').serializeArray();
            $.each(t, function () {
                data[this.name] = this.value;
            });
            console.log(data);

            var loading = layer.load(1, {shade: [0.1, '#fff']});
            $.post("{:url('')}", data, function (res) {
                layer.close(loading);
                if (res.code > 0) {
                    layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                        location.href = res.url;
                    });
                } else {
                    layer.msg(res.msg, {time: 1800, icon: 2});
                }
            });
            return false;
        });


</script>
</html>